<template>
  <div id="ban">
    <div id="ban_center">
      <ul>
        <li v-show="bHide"><router-link :to="{path:'/home',query:{user:this.buser}}">首页</router-link></li>
        <li><router-link :to="{name:'tallKnowledge'}">高中知识专栏</router-link></li>
        <li><router-link :to="{name:'talkStream'}">坤坤交流</router-link ></li>
        <li><router-link :to="{name:'educationPower'}">学历提升</router-link> </li>
        <li> <router-link :to="{name:'financialLife'}">金融生活</router-link> </li>
        <li><router-link :to="{name:'virtualComputer'}">虚拟计算机</router-link></li>
        <li><router-link :to="{name:'MessageBoard'}">人工智能</router-link></li>
        <li v-show="flag"><router-link :to="{name:'EditPassword',query:{user:this.buser}}">修改密码</router-link></li>
        <li style="margin-top: 12px;"><p style="cursor: pointer; color: white; background-color: dodgerblue;border: none;font-size: 20px;color: purple" @click="LoginOut(buser)">退出</p></li>
      </ul>
    </div>
    <div>
      <span style="font-size: 20px;display: block; float: right;margin-right: 62px; margin-top: -16px;color: white">当前用户:{{buser.account}}</span>
      <!--      <span style="font-size: 20px;display: block; float: right;margin-left: 40px; margin-top: -10px;color: white">时间:{{currentTime }}</span>-->
    </div>
  </div>
</template>

<script>
// import {mapState} from "vuex";

export default {
  name: "Banner",
  data() {
    return {
      currentTime: "",
      buser: {},
      flag: true,
      bHide:true,
    }
  },
  props:['isHide'],
  created() {
    this.bHide=this.isHide;
    this.buser=JSON.parse(localStorage.getItem("user"));
    console.log("当前对象:",this.buser);
    this.updateTime();
    setInterval(this.updateTime, 1000);
  },
  methods: {
    LoginOut(user){
      this.$store.commit('RemoveUser',user)
      this.$router.push({name: 'login'})
    },
    updateTime() {
      // 获取当前日期和时间
      var now = new Date();

      // 获取日期和时间的各个部分
      var year = now.getFullYear(); // 年
      var month = now.getMonth() + 1; // 月（getMonth() 返回的月份是从 0 开始的）
      var day = now.getDate(); // 日
      var hours = now.getHours(); // 小时
      var minutes = now.getMinutes(); // 分钟
      var seconds = now.getSeconds(); // 秒

      // 格式化时间，确保每个部分都是两位数字
      month = month < 10 ? '0' + month : month;
      day = day < 10 ? '0' + day : day;
      hours = hours < 10 ? '0' + hours : hours;
      minutes = minutes < 10 ? '0' + minutes : minutes;
      seconds = seconds < 10 ? '0' + seconds : seconds;

      // 组合成最终的时间字符串
      this.currentTime = year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
    }
  }
}
</script>


<style scoped>
#ban {
  background-color: dodgerblue;
  width: 100%;
  height: 53px;
}

#ban_center {
  //width: 1200px;
  width: 100%;
  align-content: center;
  height: 30px;
  line-height: 30px;
  margin: 0px auto;
}

#ban ul li {
  float: left;
  font-size: 19px;
  margin-top: 10px;
  margin-left: 60px;
}

</style>
